<!--  -->
<template>
    <div>

        <van-form @submit="onSubmit">

            <!-- 头 -->
            <div class="font15 mt10 pl10">
                <span class="titletext">{{ nFromdata.title }}</span>
                <div class="graytext mt10 font13">
                    <span>工单编号：</span>
                    <span class="titletext">{{ nFromdata.pmInsId }}</span>
                </div>
            </div>


            <section-header :sectionTitle="'甄选公示审批申请'" />
            <van-field readonly required name="pickApplyCode" :value="fromdata.pickApplyCode" label="甄选方案编码:"
                label-width="7em" />
            <van-field readonly required name="onePickMethod" :value="fromdata.onePickMethod" label="一级甄选方式:"
                label-width="7em" />
            <van-field readonly required name="pickActivityName" :value="fromdata.pickActivityName" label="甄选方案名称:"
                label-width="7em" />
            <van-field readonly required name="isEsAnnouncement" :value="fromdata.isEsAnnouncement" label="是否发布公告:"
                label-width="7em" />
            <van-field v-if="fromdata.isEsAnnouncement == '是'" readonly required name="applyUnit"
                :value="fromdata.applyUnit" label="采购人:" label-width="4em" />

            <van-field readonly required label="商机信息:" label-width="5em" />
            <el-table :data="fromdata.pickLinkProjectList" :header-cell-style="{ textAlign: 'center' }"
                :cell-style="{ textAlign: 'center' }" border style="width: 100%">
                <el-table-column prop="projectName" label="商机名称" />
                <el-table-column prop="businessId" label="商机编号" />
            </el-table>

            <van-field readonly required label="入选名单:" label-width="5em" />
            <el-table :data="fromdata.pickPartnerAnswerList" :header-cell-style="{ textAlign: 'center' }"
                :cell-style="{ textAlign: 'center' }" border style="width: 100%">
                <el-table-column prop="partnerName" label="合作伙伴名称" width="140" />
                <el-table-column prop="partnerCode" label="合作伙伴编码" width="150" />
                <el-table-column prop="proposePrice" label="中标金额" />
                <el-table-column prop="pickIndustry" label="甄选行业" width="130" />
                <el-table-column prop="pickScene" label="甄选场景" width="150" />
                <el-table-column prop="contact" label="联系人" />
                <el-table-column prop="contactPhone" label="联系人电话" width="130" />
                <el-table-column prop="contactEmail" label="联系人邮箱" width="150" />
            </el-table>


            <van-field v-if="fromdata.isEsAnnouncement == '是'" readonly required name="pickActivityTitle"
                :value="fromdata.pickActivityTitle" label="结果公示标题:" label-width="7em" />
            <van-field v-if="fromdata.isEsAnnouncement == '是'" readonly required autosize type="textarea" rows="1"
                name="pickPublicityContent" :value="fromdata.pickPublicityContent" label="甄选公示正文:" label-width="7em" />


            <!-- 跳转意见 -->
            <div class="left_botton">
                <button block type="button" @click="tomsg()" style="color:#60a9ec; display: inline-block;width:100%;border: 0px solid #60a9ec;border-radius: 15px 0px 0px 15px;
            padding:10px 10px 10px 15px;font-size:13px">意见</button>
            </div>

            <!-- 流转下一步 -->
            <div v-if="todotype||toRead" class="footer">
                <van-button block type="info" native-type="submit" :disabled="!canToNext"
                    style="display: inline-block; width: 100%; border: 0px solid #60a9ec">{{ buttonTitle }}</van-button>
            </div>
        </van-form>


        <!-- 当前办理人 -->
        <section-header v-if="showHistory" :sectionTitle="'当前办理人:'" />
        <div v-if="showHistory" class="font13 ptandpb10 pl16">
            <div>
                <span class="titletext font13">{{
                    historydata.MANAGER
                }}</span>
            </div>
            <div class="mt5">
                <span class="graytext font12">{{ historydata.DEPARTMENT }}</span>
            </div>
        </div>


        <!-- 审批意见 -->
        <section-header id="opinion" :sectionTitle="'审批意见:'" />
        <opinion-item :approveList="approveList"/>
    </div>
</template>


<script>

import { mapGetters } from "vuex";
import { Notify, Toast } from "vant";
import { openFileUrl } from "@/store/openFile";
import util from "@/assets/js/public";
import {
    getZXGSSPFormDetail,
    selectPickResultsNoticeByPmInsId,
    getWfOptMags,
    getWfLinkTracks,
} from "@/api/dictapi";
import SectionHeader from '../sztdzj/sztdzjDetail/section-header.vue';
import OpinionItem from '../sztdzj/sztdzjDetail/opinion-item.vue';


export default {
    data() {
        return {
            fromdata: {},
            nFromdata: {},

            params: this.$route.query,
            todotype: false,
            approveList: [],
            toRead: false,
            showHistory: false,
            historydata: {},

            buttonTitle: '流转下一步',
            canToNext: true,
        };
    },

    computed: {

        ...mapGetters(["user"]),
        ...mapGetters(["userinfo"]),
    },

    //生命周期--创建完成
    created() {
        if(this.params.pmInsType==null&&this.params.processType!=null) {
          this.params.pmInsType = this.params.processType
        }
        if (this.params.todoType == "1") {
            this.todotype = true;
        } else if (this.params.todoType == "2") {
            this.showHistory = true;
        } else if (this.params.todoType == "3") {
            this.toRead = true;
        }

        if (this.params.location == 'dict.start') {
            this.canToNext = false;
            this.buttonTitle = '暂不支持该环节,请至PC端办理';
        }

        this.getdetail();
    },

    //生命周期--挂载完成
    components: {
        SectionHeader,
        OpinionItem

    },

    //生命周期--挂载完成
    mounted() { },

    //方法调用
    methods: {

        tomsg() {
            document.getElementById('opinion').scrollIntoView({ behavior: 'smooth' })
        },

        openFileUrlfun(value) {
            this.$router.push({
                name: "fileview",
                query: {
                    openFileUrl: openFileUrl(value),
                },
            });
        },

        getdetail() {
            Toast.loading({ message: "加载中", forbidClick: false });
            getZXGSSPFormDetail(
                Object.assign(this.params, { userName: this.user.userName })
            ).then((result) => {
                this.fromdetal = {};
                Toast.clear();

                if (!result.data) {
                    Notify(result.message);
                    return;
                }

                if (result.data.data) {
                    this.nFromdata = result.data.data;
                }
            })

            selectPickResultsNoticeByPmInsId(
                Object.assign(this.params, { userName: this.user.userName })
            ).then((result) => {
                this.fromdetal = {};
                Toast.clear();
                if (!result.data) {
                    Notify(result.message);
                    return;
                }

                if (result.data.data) {
                    this.fromdata = result.data.data;
                }
            })

            getWfOptMags(Object.assign(this.params), {
                userName: this.user.userName,
            }).then((result) => {
                Toast.clear();
                if (!result.data) {
                    Notify(result.message);
                    return;
                }
                this.approveList = result.data.data.reverse();
            })

            if (this.showHistory) {

                getWfLinkTracks(Object.assign(this.params), {
                    userName: this.user.userName,
                }).then((result) => {
                    Toast.clear();
                    if (!result.data) {
                        Notify(result.message);
                        return;
                    }
                    if (result.data.data) {
                        //数据过滤，并生成新的数组
                        this.historydata = result.data.data.filter(
                            (item) => item.CURRENTSTATE == 10
                        )[0];
                        if (this.historydata) {
                            if (this.historydata.MANAGER) {
                                this.showHistory = true;
                            } else {
                                this.showHistory = false;
                            }
                        } else {
                            this.showHistory = false;
                        }
                    } else {
                        this.showHistory = false;
                    }
                })
            }
        },


        onSubmit() {

            var fromdataTwo = Object.assign(this.fromdata, { partnerAnswerList: this.fromdata.pickPartnerAnswerList, relationPickLinkProjectList:this.fromdata.pickLinkProjectList });
            delete fromdataTwo.pickPartnerAnswerList;
            delete fromdataTwo.pickLinkProjectList;

            var formSendData = { "htmlParamMap": {} };
            formSendData.htmlParamMap = fromdataTwo;
            formSendData.id = this.nFromdata.id;
            formSendData.pmInsId = this.nFromdata.pmInsId;
            formSendData.processType = this.params.pmInsType
            formSendData.workItemId = this.params.workItemId;

            var params1 = {
                kv: {
                    currentUserCode: util.encrypt(this.params.userName),
                    source: 'MOBILE',
                    location: this.params.location,
                    processInstId: this.params.processInstId,
                    processDefName: this.params.processDefName,
                    processType: this.params.pmInsType,
                },
            };

            var params2 = {
                kv: {
                    "currentUserCode": util.encrypt(this.params.userName),
                    "source": 'MOBILE',
                    "location": this.params.location,
                    "processInstId": this.params.processInstId,
                    'processType': this.params.pmInsType,
                    'receiptCode': this.params.processInstId
                },
            };

            var params3 = {
                kv: {
                    "source": 'MOBILE',
                    "currentUserCode": util.encrypt(this.params.userName),
                    "workItemId": this.params.todoType==3?"":this.params.workItemId,
                    "processInstId": this.params.processInstId,
                    "location": this.params.location,
                    "notificationId":this.params.todoType==3?this.params.wfnid:"",
                    'processType': this.params.pmInsType,
                },
            };
            localStorage.setItem('submitPageParam', JSON.stringify({
                    getDecisionsUrl: 'decisionAndUser$api$getDecisions',
                    getUserUrl: 'decisionAndUser$api$getOrgAndUser',
                    tosubmintUrl: 'applicationFormEnhance$api$startSubmitProcess',

                    getDecisionsParams: params1,
                    getUserParams: params2,
                    tosubmintParams: params3,
                    formData: formSendData,
                    fromMoa:this.params.fromMoa,
                    type:this.params.todoType==3?"toRead":"toDo"
                }))
            this.$router.push({
                name: "srqrsubmit"
            });
        },

    },
};
</script>

<style  scoped>
/* @import url();*/
</style>